package cn.wit.testalgorithms;

import java.util.HashMap;
import java.util.Map;

/**
 * 找出只3出现一次得元素
 * 
 * @author 16604
 *
 */
public class DemoFindOneNumbers {
	public static void main(String[] args) {
		int[] a = { 2, 2, 4, 2 };
		int[] b = { 0, 1, 0, 1, 0, 1, 99 };
		int[] c = { 43, 16, 45, 89, 45, -2147483648, 45, 2147483646, -2147483647, -2147483648, 43, 2147483647,
				-2147483646, -2147483648, 89, -2147483646, 89, -2147483646, -2147483647, 2147483646, -2147483647, 16,
				16, 2147483646, 43 };
		System.out.println(singleNumber(a));
		System.out.println(singleNumber(b));
		System.out.println(singleNumber(c));
	}

	public static int singleNumber(int[] nums) {
		int count=0;
		for (int i = 0; i < nums.length; i++) {
			count = 0;
			for (int j = 0; j < nums.length; j++) {
				if (i == j) {
					continue;
				} else if (nums[i] == nums[j]) {
					count++;
					if (count >= 1)
						break;
				}
			}
			if (count == 0) {
				// if(map.get(i)==)
				return nums[i];
			}
		}
		throw new IllegalArgumentException("No  solution");
	}
}
